package cn.tedu.zhyl.system.service.impl;

import cn.tedu.zhyl.base.help.TreeHelper;
import cn.tedu.zhyl.system.mapper.SysDeptMapper;
import cn.tedu.zhyl.system.pojo.dto.SysDeptQuery;
import cn.tedu.zhyl.system.pojo.vo.SysDeptVo;
import cn.tedu.zhyl.system.service.SysDeptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class SysDeptServiceImpl implements SysDeptService {
    private static final Logger log = LoggerFactory.getLogger(SysDeptServiceImpl.class);
    @Autowired
    private SysDeptMapper sysDeptMapper;
    @Override
    public List<String> findDeptList(List<String> query) {
        List<String> list = new ArrayList<>();
        log.debug("查询部门名参数：{}",query);
        if (!query.isEmpty()){
            for (String s : query){
                SysDeptVo sss = sysDeptMapper.findByDeptNo(s);
                if(sss!=null){
                    list.add(sss.getDeptName());
                }
            }
        }
        log.debug("部门名数组为:{}",list);
        return list;
    }

    @Override
    public List<SysDeptVo> getTreeDeptList() {
        List<SysDeptVo> list = sysDeptMapper.select(null);
        List<SysDeptVo> treeList = TreeHelper.buildTree(list,"100000000000000");
        return treeList;
    }

    @Override
    public List<SysDeptVo> select() {
        List<SysDeptVo> list = sysDeptMapper.selectAll();
        return list;
    }
}
